package com.hmis.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hmis.domain.PrescriptionMedicine;
import com.hmis.service.PrescriptionMedicineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@Controller
public class PresciptionMedicineDAO implements InitializingBean {

    public static PrescriptionMedicineService prescriptionMedicineService;
    public static PresciptionMedicineDAO presciptionMedicineDAO;
    @Autowired
    private PrescriptionMedicineService prescriptionMedicine;

    public List<PrescriptionMedicine> listByPrescriptionId(Long prescriptionId) {
        LambdaQueryWrapper<PrescriptionMedicine> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PrescriptionMedicine::getPrescriptionId, prescriptionId);
        return prescriptionMedicineService.list(queryWrapper);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        prescriptionMedicineService = prescriptionMedicine;
        presciptionMedicineDAO = this;
    }

    public void save(PrescriptionMedicine prescriptionMedicine) {
        prescriptionMedicineService.save(prescriptionMedicine);
    }
}
